home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / intuition / intuition_init.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  8KB  |  339 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: intuition_init.c,v 1.6 1996/09/13 17:57:09 digulla Exp $
  4.     $Log: intuition_init.c,v $
  5.     Revision 1.6  1996/09/13 17:57:09  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.5  1996/09/11 16:54:31  digulla
  9.     Always use __AROS_SLIB_ENTRY() to access shared external symbols, because
  10.     some systems name an external symbol "x" as "_x" and others as "x".
  11.     (The problem arises with assembler symbols which might differ)
  12.  
  13.     Revision 1.4  1996/08/29 13:33:31  digulla
  14.     Moved common code from driver to Intuition
  15.     More docs
  16.  
  17.     Revision 1.3  1996/08/28 17:55:37  digulla
  18.     Proportional gadgets
  19.     BOOPSI
  20.  
  21.     Revision 1.2  1996/08/23 17:24:11  digulla
  22.     Opening intuition.library called intui_init() instead of intui_open(). Ooops.
  23.  
  24.     Revision 1.1  1996/08/13 15:37:26  digulla
  25.     First function for intuition.library
  26.  
  27.  
  28.     Desc:
  29.     Lang:
  30. */
  31. #define AROS_ALMOST_COMPATIBLE
  32. #include <string.h>
  33. #include <exec/lists.h>
  34. #include <exec/resident.h>
  35. #include <exec/memory.h>
  36. #include <exec/execbase.h>
  37. #include <clib/exec_protos.h>
  38. #include <clib/intuition_protos.h>
  39. #include <dos/dos.h>
  40. #include <dos/dostags.h>
  41. #include <clib/dos_protos.h>
  42. #ifndef INTUITION_CLASSES_H
  43. #   include <intuition/classes.h>
  44. #endif
  45. #ifndef UTILITY_HOOKS_H
  46. #   include <utility/hooks.h>
  47. #endif
  48. #include "intuition_intern.h"
  49.  
  50. static const char name[];
  51. static const char version[];
  52. static const APTR inittabl[4];
  53. static void *const Intuition_functable[];
  54. struct IntuitionBase *__AROS_SLIB_ENTRY(init,Intuition) ();
  55. extern const char Intuition_end;
  56. extern struct DosBase * DOSBase;
  57.  
  58. extern int  intui_init (struct IntuitionBase *);
  59. extern int  intui_open (struct IntuitionBase *);
  60. extern void intui_close (struct IntuitionBase *);
  61. extern void intui_expunge (struct IntuitionBase *);
  62.  
  63. static ULONG rootDispatcher (Class *, Object *, Msg);
  64. static struct IntuitionBase * IntuiBase;
  65.  
  66. int Intuition_entry(void)
  67. {
  68.     /* If the library was executed by accident return error code. */
  69.     return -1;
  70. }
  71.  
  72. const struct Resident Intuition_resident=
  73. {
  74.     RTC_MATCHWORD,
  75.     (struct Resident *)&Intuition_resident,
  76.     (APTR)&Intuition_end,
  77.     RTF_AUTOINIT,
  78.     39,
  79.     NT_LIBRARY,
  80.     0,
  81.     (char *)name,
  82.     (char *)&version[6],
  83.     (ULONG *)inittabl
  84. };
  85.  
  86. static const char name[]="intuition.library";
  87.  
  88. static const char version[]="$VER: intuition.library 39.0 (12.8.96)\n\015";
  89.  
  90. static const APTR inittabl[4]=
  91. {
  92.     (APTR)sizeof(struct IntIntuitionBase),
  93.     (APTR)Intuition_functable,
  94.     NULL,
  95.     &__AROS_SLIB_ENTRY(init,Intuition)
  96. };
  97.  
  98. static Class rootclass =
  99. {
  100.     { { NULL, NULL }, rootDispatcher, NULL, NULL },
  101.     0,        /* reserved */
  102.     NULL,    /* No superclass */
  103.     (ClassID)ROOTCLASS,  /* ClassID */
  104.  
  105.     0, 0,    /* No offset and size */
  106.  
  107.     0,        /* UserData */
  108.     0,        /* SubClassCount */
  109.     0,        /* ObjectCount */
  110.     0,        /* Flags */
  111. };
  112.  
  113. void intui_ProcessEvents (void);
  114. static struct Screen WB;
  115.  
  116. struct Process * inputDevice;
  117.  
  118. __AROS_LH2(struct IntuitionBase *, init,
  119.  __AROS_LHA(struct IntuitionBase *, IntuitionBase, D0),
  120.  __AROS_LHA(BPTR,               segList,   A0),
  121.        struct ExecBase *, sysBase, 0, Intuition)
  122. {
  123.     __AROS_FUNC_INIT
  124.     struct TagItem inputTask[]=
  125.     {
  126.     { NP_Entry,    (IPTR)intui_ProcessEvents },
  127.     { NP_Input,    0L },
  128.     { NP_Output,    0L },
  129.     { NP_Name,    (IPTR)"input.device" },
  130.     { NP_StackSize, 100000 },
  131.     { NP_Priority,    50 },
  132.     { TAG_END, 0 }
  133.     };
  134.  
  135.     IntuiBase = IntuitionBase;
  136.     SysBase = sysBase;
  137.  
  138.     NEWLIST (PublicClassList);
  139.  
  140.     memset (&WB, 0, sizeof (struct Screen));
  141.  
  142.     IntuitionBase->FirstScreen =
  143.     IntuitionBase->ActiveScreen = &WB;
  144.  
  145.     GetPrivIBase(IntuitionBase)->WorkBench = &WB;
  146.  
  147.     if (!intui_init (IntuitionBase))
  148.     return NULL;
  149.  
  150.     /* The rootclass is created statically */
  151.     AddClass (&rootclass);
  152.  
  153.     inputDevice = CreateNewProc (inputTask);
  154.  
  155.     /* You would return NULL if the init failed */
  156.     return IntuitionBase;
  157.     __AROS_FUNC_EXIT
  158. }
  159.  
  160. __AROS_LH1(struct IntuitionBase *, open,
  161.  __AROS_LHA(ULONG, version, D0),
  162.        struct IntuitionBase *, IntuitionBase, 1, Intuition)
  163. {
  164.     __AROS_FUNC_INIT
  165.  
  166.     /* Keep compiler happy */
  167.     version=0;
  168.  
  169.     if (!GfxBase)
  170.     {
  171.     if (!(GfxBase = (void *)OpenLibrary (GRAPHICSNAME, 39)) )
  172.         return NULL;
  173.     }
  174.  
  175.     if (!intui_open (IntuitionBase))
  176.     return NULL;
  177.  
  178.     /* I have one more opener. */
  179.     IntuitionBase->LibNode.lib_OpenCnt++;
  180.     IntuitionBase->LibNode.lib_Flags&=~LIBF_DELEXP;
  181.  
  182.     /* You would return NULL if the open failed. */
  183.     return IntuitionBase;
  184.     __AROS_FUNC_EXIT
  185. }
  186.  
  187. __AROS_LH0(BPTR, close,
  188.        struct IntuitionBase *, IntuitionBase, 2, Intuition)
  189. {
  190.     __AROS_FUNC_INIT
  191.  
  192.     /* I have one fewer opener. */
  193.     if(!--IntuitionBase->LibNode.lib_OpenCnt)
  194.     {
  195.     intui_close (IntuitionBase);
  196.  
  197.     /* Delayed expunge pending? */
  198.     if(IntuitionBase->LibNode.lib_Flags&LIBF_DELEXP)
  199.         /* Then expunge the library */
  200.         return expunge();
  201.     }
  202.     return 0;
  203.     __AROS_FUNC_EXIT
  204. }
  205.  
  206. __AROS_LH0(BPTR, expunge,
  207.        struct IntuitionBase *, IntuitionBase, 3, Intuition)
  208. {
  209.     __AROS_FUNC_INIT
  210.  
  211.     BPTR ret;
  212.  
  213.     /* Test for openers. */
  214.     if(IntuitionBase->LibNode.lib_OpenCnt)
  215.     {
  216.     /* Set the delayed expunge flag and return. */
  217.     IntuitionBase->LibNode.lib_Flags|=LIBF_DELEXP;
  218.     return 0;
  219.     }
  220.  
  221.     intui_expunge (IntuitionBase);
  222.  
  223.     /* Get rid of the library. Remove it from the list. */
  224.     Remove(&IntuitionBase->LibNode.lib_Node);
  225.  
  226.     /* Get returncode here - FreeMem() will destroy the field. */
  227.     ret=0L;
  228.  
  229.     /* Free the memory. */
  230.     FreeMem((char *)IntuitionBase-IntuitionBase->LibNode.lib_NegSize,
  231.         IntuitionBase->LibNode.lib_NegSize+IntuitionBase->LibNode.lib_PosSize);
  232.  
  233.     return ret;
  234.     __AROS_FUNC_EXIT
  235. }
  236.  
  237. __AROS_LH0I(int, null,
  238.         struct IntuitionBase *, IntuitionBase, 4, Intuition)
  239. {
  240.     __AROS_FUNC_INIT
  241.     return 0;
  242.     __AROS_FUNC_EXIT
  243. }
  244.  
  245. #undef IntuitionBase
  246. #define IntuitionBase    IntuiBase
  247.  
  248. /******************************************************************************
  249.  
  250.     NAME */
  251.     static IPTR rootDispatcher (
  252.  
  253. /*  SYNOPSIS */
  254.     Class  * cl,
  255.     Object * o,
  256.     Msg     msg)
  257.  
  258. /*  FUNCTION
  259.     internal !
  260.  
  261.     Processes all messages sent to the RootClass. Unknown messages are
  262.     silently ignored.
  263.  
  264.     INPUTS
  265.     cl - Pointer to the RootClass
  266.     o - This object was the destination for the message in the first
  267.         place
  268.     msg - This is the message.
  269.  
  270.     RESULT
  271.     Processes the message. The meaning of the result depends on the
  272.     type of the message.
  273.  
  274.     NOTES
  275.     This is a good place to debug BOOPSI objects since every message
  276.     should eventually show up here.
  277.  
  278.     EXAMPLE
  279.  
  280.     BUGS
  281.  
  282.     SEE ALSO
  283.  
  284.     HISTORY:
  285.     14.09.93    ada created
  286.  
  287. ******************************************************************************/
  288. {
  289.     IPTR retval = 0;
  290.  
  291.     switch (msg->MethodID)
  292.     {
  293.     case OM_NEW: {
  294.     cl = _OBJECT(o)->o_Class;
  295.  
  296.     /* Nur Speicher besorgen. Im Object steht, wieviel.
  297.        (Das Object ist keines. Es ist der Class-Pointer selbst !) */
  298.     retval = (IPTR) AllocMem (cl->cl_InstOffset
  299.         + cl->cl_InstSize
  300.         + sizeof (struct _Object)
  301.         , MEMF_ANY
  302.         );
  303.  
  304.     retval = (IPTR) BASEOBJECT(retval);
  305.     break; }
  306.  
  307.     case OM_DISPOSE:
  308.     /* Speicher freigeben. Aufrufer ist verantwortlich,
  309.        dass bereits alles andere freigegeben wurde ! */
  310.     FreeMem (_OBJECT(o)
  311.         , cl->cl_InstOffset
  312.         + cl->cl_InstSize
  313.         + sizeof (struct _Object)
  314.         );
  315.     break;
  316.  
  317.     case OM_ADDTAIL:
  318.     /* Fuege <o> an Liste an. */
  319.     AddTail (((struct opAddTail *)msg)->opat_List,
  320.             (struct Node *) _OBJECT(o));
  321.     break;
  322.  
  323.     case OM_REMOVE:
  324.     /* Entferne Object aus der Liste */
  325.     Remove ((struct Node *) _OBJECT(o));
  326.     break;
  327.  
  328.     default:
  329.     /* Ignore */
  330.     break;
  331.  
  332.     } /* switch */
  333.  
  334.     return (retval);
  335. } /* rootDispatcher */
  336.  
  337.  
  338.  
  339.